﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="CtrlComment.ascx.cs"
    Inherits="Aij1.UserControls.CtrlComment" %>
<script type="text/javascript" src="Scripts/jquery-1.4.1.min.js"></script>
<script type="text/javascript">
    //<!--
    var commentContainer;
    var commentItemTemplate;
    var totalCount;

    function submitComment() {
        var comment = $("#txtComment").val();
        if (comment == '')
            commentContainer.append('<div style="text-align:center;" class="tips"> 正在读取评论，请稍等...</div>');
        else
           commentContainer.append('<div style="text-align:center;" class="tips"> 正在提交评论，请稍等...</div>');
        $('#btnSubmit').enabled = false;
         $.ajax({
            type: "POST",
            url: "AddComments.ashx?CID=" + <%=Article.Oid %> + "&rnd=" + new Date().getUTCMilliseconds(),
            data: "Comment=" + comment,
            dataType: "json",
            success: function (msg) { showComment(msg); },
            async: true
        });
        $('#btnSubmit').enabled =true;
        $('#txtComment').val('');
    }

    function showComment(comments) {
        commentContainer.empty();
        if (comments.length == 0) {
            commentContainer.html('<div class="comment">目前还没有评论。</div>');
        }
        for (var i = 0; i < comments.length; i++) {
            addItemToComment(comments[i]);
        }
    }

    function addItemToComment(comment) {
        var newchild = commentItemTemplate.clone();
        newchild.id = "comment" + comment.level;
        newchild.html(newchild.html().replace(/\{level\}/g, comment.level));
        newchild.html(newchild.html().replace(/\{name\}/g, comment.name));
        newchild.html(newchild.html().replace(/\{time\}/g, comment.time));
        newchild.html(newchild.html().replace(/\{comment\}/g, comment.comment));
        newchild.appendTo(commentContainer);
        newchild.show();
    }

    $(document).ready(function () {
        commentContainer = $("#divCommentList");
        commentItemTemplate = $("#commentItemTemplate");
        submitComment();
    });

    //-->
</script>
<div id="divCommentList">
    <div id="commentItemTemplate" style="display: none;" class="comment">
        <span style="font-size: 12px">#{level}F <b>{name}</b> 于 {time} 发表评论:</span><br />
        <div style="font-size: 14px">
            {comment}</div>
    </div>
</div>
<div style="font-size: 12px">
    发表评论(文明上网，登录发贴):<br />
    <textarea cols="70" rows="5" id="txtComment">
</textarea><br />
    <div style="margin-top: 0.3em;margin-bottom:.5em;" class='clearfix'>
        <%if (C == null)
          { %>
        <div style="float:left;line-height:24px;">您在登录后才能发表评论，谢谢！</div> <div style="float:left">
            <input type="image" style="width: 120px; height: 24px; border: 0;"
                src="http://qzonestyle.gtimg.cn/qzone/vas/opensns/res/img/Connect_logo_3.png"
                onclick="loginToQQ();return false;" /></div>
        <%}
          else
          { %>
        网友评论仅供其表达个人看法，并不表明本站同意其观点或证实其描述。
        <input id="btnSubmit" type="button" value="提交评论" onclick="submitComment();" style="width: 80px;
            height: 24px;" />
        <%} %>
    </div>
</div>
